﻿//InitArray.cs
//Initializing rectanglar and jagged ararys
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InitArray
{
    class Program
    {
        static void Main(string[] args)
        {
            //with rectanglar arrays
            //every column must be the same length
            int[,] rectanglar = { { 0, 1, 4 }, { 5, 8, 9 }, { 4, 0, 4 } };

            //with jagged arrays
            //we need to use "new int[]" for every row 
            //but every column do not need to be the same length
            int[][] jagged = {  new int[]{1,4},
                                new int[]{4,5,8},
                                new int[]{4,2,8,9}};

            OutputArray(rectanglar);
            Console.WriteLine();
            OutputArray(jagged);

            Console.ReadKey();
        }//end method Main

        //output rectanglar arrays
        public static void OutputArray(int[,] array)
        {
            int row = array.GetLength(0);
            int column = array.GetLength(1);

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    Console.Write("{0}  ", array[i, j]);
                }

                Console.WriteLine();
            }
        }//end method OutputArray for rectanglar arrays

        //output jagged array
        public static void OutputArray(int[][] array)
        {
            foreach (var row in array)
            {
                foreach (var element in row)
                {
                    Console.Write("{0}  ", element);
                }//end for

                Console.WriteLine();
            }//end outer for
        }//end method OutputArray for jagged array
    }
}
